home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C++ / Code Resources / Windows 95 MDEF / Sourcery / WinFun95 / Win95Look.c next >
C/C++ Source or Header  |  1996-06-12  |  8KB  |  303 lines

  1. #include "Win95Look.h"
  2.  
  3. // ---------------------------------------------------------------------------
  4.  
  5. void W95DrawChar(
  6.     char theChar,
  7.     const RGBColor *textColor,
  8.     const RGBColor *embossColor) {
  9.     
  10.     W95DrawText((Ptr)&theChar, 1, textColor, embossColor);
  11. } // END W95DrawChar
  12.  
  13. // ---------------------------------------------------------------------------
  14.  
  15. void W95DrawText(
  16.     char *text,
  17.     unsigned short length,
  18.     const RGBColor *textColor,
  19.     const RGBColor *embossColor) {
  20.     
  21.     RGBColor saveFore;
  22.     short saveTxMode;
  23.     GrafPtr savePort;
  24.     short curHLoc, curVLoc;
  25.     
  26.     // Get current port settings
  27.     GetPort(&savePort);
  28.     saveTxMode = savePort->txMode;
  29.     GetForeColor(&saveFore);
  30.     curHLoc = savePort->pnLoc.h;
  31.     curVLoc = savePort->pnLoc.v;
  32.     TextMode(srcOr);
  33.     
  34.     Move(1, 1);
  35.     RGBForeColor(embossColor);
  36.     // Draw emboss text
  37.     DrawText(text, 0, length);
  38.     
  39.     MoveTo(curHLoc, curVLoc);
  40.     RGBForeColor(textColor);
  41.     // Draw text
  42.     DrawText(text, 0, length);
  43.  
  44.     // Restore port settings
  45.     TextMode(saveTxMode);
  46.     RGBForeColor(&saveFore);
  47. } // END W95DrawText
  48.  
  49. // ---------------------------------------------------------------------------
  50.  
  51. void W95DrawTextAt(
  52.     char *text,
  53.     unsigned short length,
  54.     short h,
  55.     short v,
  56.     const RGBColor *textColor,
  57.     const RGBColor *embossColor) {
  58.     
  59.     MoveTo(h, v);
  60.     W95DrawText(text, length, textColor, embossColor);
  61. } // END W95DrawTextAt
  62.  
  63. // ---------------------------------------------------------------------------
  64.  
  65. /*
  66.     We special case for horizontal and vertical lines.
  67.     For horizontal lines, the hilite line is one pixel below the line.
  68.     For vertical lines, the hilite line is drawn one pixel to the right.
  69.     Other lines, the hilite line is drawn down and right one pixel.
  70. */
  71. void W95LineTo(
  72.     short h,
  73.     short v,
  74.     const RGBColor *lineColor,
  75.     const RGBColor *hiliteColor) {
  76.  
  77.     GrafPtr savePort;
  78.     RGBColor saveFore;
  79.     short curHLoc, curVLoc;
  80.     
  81.     GetPort(&savePort);
  82.     GetForeColor(&saveFore);
  83.     curHLoc = savePort->pnLoc.h;
  84.     curVLoc = savePort->pnLoc.v;
  85.     
  86.     // Draw hilite line
  87.     RGBForeColor(hiliteColor);
  88.     if (curHLoc == h) {
  89.         // Vertical line
  90.         Move(1, 0);
  91.         LineTo(h+1, v);
  92.     }
  93.     else if (curVLoc == v) {
  94.         // Horizontal line
  95.         Move(0, 1);
  96.         LineTo(h, v+1);
  97.     }
  98.     else {
  99.         Move(1, 1);
  100.         LineTo(h+1, v+1);
  101.     }
  102.     
  103.     // Draw shadow line
  104.     RGBForeColor(lineColor);
  105.     MoveTo(curHLoc, curVLoc);
  106.     LineTo(h, v);
  107.     
  108.     // Restore fore color
  109.     RGBForeColor(&saveFore);
  110. } // END W95LineTo
  111.  
  112. // ---------------------------------------------------------------------------
  113.  
  114. void W95DrawRect(
  115.     const Rect *frame,
  116.     const RGBColor *lineColor,
  117.     const RGBColor *hiliteColor) {
  118.  
  119.     // Since the line-drawing saves and restore the colors, there's no
  120.     // need for us to do it. However, we have to make sure we draw
  121.     // only inside the frame...
  122.     
  123.     // Draw left
  124.     MoveTo(frame->left, frame->top);
  125.     W95LineTo(frame->left, frame->bottom, lineColor, hiliteColor);
  126.     
  127.     // Draw top
  128.     MoveTo(frame->left, frame->top);
  129.     W95LineTo(frame->left+1, frame->top, lineColor, hiliteColor);
  130.     
  131.     // Draw right
  132.     MoveTo(frame->right-2, frame->top);
  133.     W95LineTo(frame->right-2, frame->bottom, lineColor, hiliteColor);
  134.     
  135.     // Draw bottom
  136.     MoveTo(frame->left, frame->bottom-2);
  137.     W95LineTo(frame->right-1, frame->bottom-2, lineColor, hiliteColor);
  138. } // END W95DrawRect
  139.  
  140. // ---------------------------------------------------------------------------
  141.  
  142. /*
  143.     Draw a rightward-pointing arrow.
  144. */
  145.  
  146. void W95DrawTriangleRight(
  147.     const Rect *triangleBounds,
  148.     Boolean exactWin95Look,
  149.     const RGBColor *lineColor,
  150.     const RGBColor *hiliteColor,
  151.     const RGBColor *fillColor) {
  152.  
  153.     short halfHeightLoc;
  154.     RGBColor saveFore;
  155.     
  156.     GetForeColor(&saveFore);
  157.  
  158.     halfHeightLoc = triangleBounds->top +
  159.         ((triangleBounds->bottom - triangleBounds->top) / 2);
  160.  
  161.     if (!exactWin95Look) {
  162.         RGBForeColor(lineColor);
  163.         MoveTo(triangleBounds->left, triangleBounds->top);
  164.         LineTo(triangleBounds->right, halfHeightLoc);
  165.         MoveTo(triangleBounds->left, triangleBounds->top);
  166.         LineTo(triangleBounds->left, triangleBounds->bottom);
  167.         RGBForeColor(hiliteColor);
  168.         //MoveTo(triangleBounds->left, triangleBounds->bottom);
  169.         LineTo(triangleBounds->right, halfHeightLoc);
  170.     }
  171.     else {
  172.         RgnHandle triangle;
  173.  
  174.         triangle = NewRgn();
  175.         OpenRgn();
  176.  
  177.         MoveTo(triangleBounds->left, triangleBounds->top);
  178.         LineTo(triangleBounds->right, halfHeightLoc);
  179.         MoveTo(triangleBounds->left, triangleBounds->top);
  180.         LineTo(triangleBounds->left, triangleBounds->bottom);
  181.         //MoveTo(triangleBounds->left, triangleBounds->bottom);
  182.         LineTo(triangleBounds->right, halfHeightLoc);
  183.         
  184.         CloseRgn(triangle);
  185.         RGBForeColor(fillColor);
  186.         PaintRgn(triangle);
  187.         DisposeRgn(triangle);
  188.     }
  189.     
  190.     RGBForeColor(&saveFore);
  191. } // END W95DrawTriangleRight
  192.  
  193. // ---------------------------------------------------------------------------
  194.  
  195. /*
  196.     Draw a downward-pointing arrow.
  197. */
  198. void W95DrawTriangleDown(
  199.     const Rect *triangleBounds,
  200.     Boolean exactWin95Look,
  201.     const RGBColor *lineColor,
  202.     const RGBColor *hiliteColor,
  203.     const RGBColor *fillColor) {
  204.  
  205.     short halfWidthLoc;
  206.     RGBColor saveFore;
  207.     
  208.     GetForeColor(&saveFore);
  209.  
  210.     halfWidthLoc = triangleBounds->left +
  211.         ((triangleBounds->right - triangleBounds->left) / 2);
  212.  
  213.     if (!exactWin95Look) {
  214.         RGBForeColor(lineColor);
  215.         MoveTo(triangleBounds->left, triangleBounds->top);
  216.         LineTo(triangleBounds->right, triangleBounds->top);
  217.         MoveTo(triangleBounds->left, triangleBounds->top);
  218.         LineTo(halfWidthLoc, triangleBounds->bottom);
  219.         RGBForeColor(hiliteColor);
  220.         LineTo(triangleBounds->right, triangleBounds->top);
  221.         //LineTo(halfWidthLoc, triangleBounds->bottom);
  222.     }
  223.     else {
  224.         RgnHandle triangle;
  225.  
  226.         triangle = NewRgn();
  227.         OpenRgn();
  228.  
  229.         MoveTo(triangleBounds->left, triangleBounds->top);
  230.         LineTo(triangleBounds->right, triangleBounds->top);
  231.         MoveTo(triangleBounds->left, triangleBounds->top);
  232.         LineTo(halfWidthLoc, triangleBounds->bottom);
  233.         LineTo(triangleBounds->right, triangleBounds->top);
  234.         //LineTo(halfWidthLoc, triangleBounds->bottom);
  235.         
  236.         CloseRgn(triangle);
  237.         RGBForeColor(fillColor);
  238.         PaintRgn(triangle);
  239.         DisposeRgn(triangle);
  240.     }
  241.     
  242.     RGBForeColor(&saveFore);
  243. } // END W95DrawTriangleDown
  244.  
  245. // ---------------------------------------------------------------------------
  246.  
  247. void W95DrawEmbossedButton(
  248.     const Rect *btnRect,
  249.     Boolean pushedIn,
  250.     const RGBColor *baseColor,
  251.     const RGBColor *hiliteColor,
  252.     const RGBColor *shadowColor,
  253.     const RGBColor *frameColor) {
  254.  
  255.     RGBColor saveFore;
  256.     RGBColor frameRGB;
  257.     
  258.     GetForeColor(&saveFore);
  259.     
  260.     RGBForeColor(shadowColor);
  261.     // Outer top shadow line
  262.     MoveTo(btnRect->left, btnRect->top);
  263.     LineTo(btnRect->right, btnRect->top);
  264.     // Outer left shadow line
  265.     MoveTo(btnRect->left, btnRect->top);
  266.     LineTo(btnRect->left, btnRect->bottom);
  267.     
  268.     // Inner right shadow line
  269.     MoveTo(btnRect->right-1, btnRect->top+3);
  270.     LineTo(btnRect->right-1, btnRect->bottom-1);
  271.     // Inner bottom shadow line
  272.     MoveTo(btnRect->left+3, btnRect->bottom-1);
  273.     LineTo(btnRect->right-1, btnRect->bottom-1);
  274.     
  275.     RGBForeColor(hiliteColor);
  276.     // Inner top hilite line
  277.     MoveTo(btnRect->left+2, btnRect->top+2);
  278.     LineTo(btnRect->right-1, btnRect->top+2);
  279.     // Inner left hilite line
  280.     MoveTo(btnRect->left+2, btnRect->top+2);
  281.     LineTo(btnRect->left+2, btnRect->bottom-1);
  282.     
  283.     if (frameColor == NULL) {
  284.         // Default: black frame
  285.         frameRGB.red = frameRGB.green = frameRGB.blue = 0x0000;
  286.     }
  287.     else
  288.         frameRGB = *frameColor;
  289.  
  290.     RGBForeColor(&frameRGB);
  291.     // Left frame
  292.     MoveTo(btnRect->left+1, btnRect->bottom);
  293.     LineTo(btnRect->left+1, btnRect->top+1);
  294.     // Top frame
  295.     LineTo(btnRect->right, btnRect->top+1);
  296.     // Right frame
  297.     LineTo(btnRect->right, btnRect->bottom);
  298.     // Bottom frame
  299.     LineTo(btnRect->left+1, btnRect->bottom);
  300.     
  301.     // Restore fore color
  302.     RGBForeColor(&saveFore);
  303. } // END W95DrawEmbossedButton